package com.gaoyi.basemodule.baseUtil;

import com.gaoyi.basemodule.baseconstant.Constants;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.ClassicsHeader;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;

public class SmartRefreshUtil {

    /**
     * 在Application初始化
     */
    public static void init(){
        SmartRefreshLayout.setDefaultRefreshHeaderCreator((context, layout) -> new ClassicsHeader(context));
        SmartRefreshLayout.setDefaultRefreshFooterCreator((context, layout) -> new ClassicsFooter(context));
    }

    /**
     * 更新SmartRefreshLayout狀態
     */
    public static void refreshSmartRefreshLayout(SmartRefreshLayout smartRefreshLayout) {
        if (smartRefreshLayout.getTag() == null) {
            return;
        }
        if (smartRefreshLayout.getTag().equals(Constants.REFRESH)) {
            smartRefreshLayout.finishRefresh();
        } else {
            smartRefreshLayout.finishLoadMore();
        }
    }

    public static int getOffset(int pageInx) {
        return (pageInx - 1) * 10;
    }

    public static int getLimit() {
        return 10;
    }
}
